<template>
  <main class="mission_planing_container">
    <h2>知识类型添加</h2>

    <el-form inline size="small" class="demo-form-inline aside">
      <el-form-item label="知识类型名称">
        <el-input
          v-model="queryParam.typeName"
          maxlength="30"
          v-max-length-tip="30"
          v-no-space
          clearable
          placeholder="请输入知识类型"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleSearch" class="el-button-search"
          >查询</el-button
        >
        <el-button type="primary" @click="handleReset" class="el-button-search"
          >重置</el-button
        >
      </el-form-item>
      <el-button
        size="small"
        style="float: right;"
        type="primary"
        @click="handleAddKnowledgeType"
        class="el-button-search"
        >添加知识类型</el-button
      >
    </el-form>
    <el-row>
      <!--    表格数据区-->
      <el-table
        v-loading="loading"
        :data="TreeList"
        row-key="id"
        :default-expand-all="isExpandAll"
        :tree-props="{ children: 'childrenList', hasChildren: 'hasChildren' }"
      >
        <el-table-column label="序号" type="index" width="80"></el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="typeName"
          label="类型名称"
        ></el-table-column>
        <el-table-column show-overflow-tooltip prop="color" label="颜色">
          <template slot-scope="scope">
            <el-button :style="{ background: scope.row.color, border: 'none' }"
              >颜色</el-button
            >
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="createTime"
          label="创建时间"
        ></el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="action"
          label="操作"
          width="180"
        >
          <template slot-scope="scope">
            <span class="operation" @click="handleOpenModal(scope.row, 'add')"
              >添加</span
            >
            <el-divider direction="vertical"></el-divider>
            <span class="operation" @click="handleOpenModal(scope.row, 'edit')"
              >编辑</span
            >
            <el-divider direction="vertical"></el-divider>
            <span
              class="operation"
              @click="handleDeleteKnowledgeType(scope.row)"
              >删除</span
            >
          </template>
        </el-table-column>
      </el-table>
    </el-row>

    <el-dialog
      append-to-body
      :visible.sync="dialogVisible"
      :title="Isflag == true ? '编辑知识类型' : '添加知识类型'"
    >
      <el-form
        ref="addFormRef"
        :model="addform"
        label-width="126px"
        class="dialog-form"
        inline
      >
        <el-form-item
          label="知识类型名称"
          prop="typeName"
          :rules="{ required: true, message: '请输入', trigger: 'blur' }"
        >
          <el-input
            maxlength="30"
            v-model="addform.typeName"
            v-max-length-tip="30"
            v-no-space
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item
          label="排序"
          prop="sort"
          :rules="{ required: true, message: '请输入', trigger: 'blur' }"
        >
          <el-input-number
            :min="1"
            :max="100"
            v-max-length-tip="3"
            v-no-space
            clearable
            v-model="addform.sort"
          ></el-input-number>
        </el-form-item>
        <el-form-item
          label="颜色"
          prop="color"
          :rules="{ required: true, message: '请选择', trigger: 'change' }"
        >
          <el-color-picker v-model="addform.color"></el-color-picker>
        </el-form-item>
      </el-form>

      <div style="margin:20px 0">
        <el-button type="primary" size="small" @click="handleAdd"
          >添加</el-button
        >
      </div>
      <el-table :data="tableList" stripe :height="'30vh'" border>
        <el-table-column type="index" label="序号" width="80"></el-table-column>
        <el-table-column prop="name" label="名称">
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.name"
              maxlength="30"
              v-max-length-tip="30"
              v-no-space
              clerable
              @input="handleInputChange($event, scope.row)"
            ></el-input>
          </template>
        </el-table-column>
        <el-table-column prop="inputMethod" label="输入方式">
          <template slot-scope="scope">
            <el-select v-model="scope.row.inputMethod" disabled>
              <el-option
                v-for="item in inputMethodOption"
                :label="item.label"
                :value="item.value"
                :key="item.value"
              ></el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column label="操作" prop="action">
          <template slot-scope="scope">
            <el-button
              type="primary"
              size="small"
              @click="handleDelete(scope.$index, scope.row)"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleSaveKnowledgeType('addFormRef')"
          >确定</el-button
        >
        <el-button @click="handleCloseModal('addFormRef')">取消</el-button>
      </span>
    </el-dialog>
  </main>
</template>

<script src="./index.js"></script>
<style src="../knowledgeAddition/index.scss" lang="scss" scoped></style>
